package com.czk.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.czk.model.user.UserInfo;
import com.czk.vo.user.UserInfoQueryVo;
import com.czk.yygh.common.result.Result;
import com.czk.yygh.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/11/25 22:56
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户的分页查询
     *
     * @param page
     * @param limit
     * @param userInfoQueryVo
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageParams = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.selectPage(pageParams, userInfoQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 用户锁定与解锁定
     *
     * @param id
     * @param status
     * @return
     */
    @GetMapping("/lock/{id}/{status}")
    public Result lock(@PathVariable Long id,
                       @PathVariable Integer status) {
        userInfoService.lock(id, status);
        return Result.ok();
    }

    /**
     * 查询用户信息
     *
     * @param id
     * @return
     */
    @GetMapping("/show/{id}")
    public Result show(@PathVariable Long id) {
        Map<String, Object> map = userInfoService.show(id);
        return Result.ok(map);
    }

    /**
     * 用户认证
     *
     * @param userId
     * @param authStatus
     * @return
     */
    @GetMapping("/approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,
                           @PathVariable Integer authStatus) {
        userInfoService.approval(userId, authStatus);
        return Result.ok();
    }
}
